<template>
	<div id='system' v-loading="loading">
		<div class="content-top">
			<span class="h1">查询分析</span>
			<span class="h2">分配统计查询</span>
		</div>
		<div class="top-btn clearfix">
			<div class="left-content">
				<span class="tip">分配统计查询</span>
				<el-radio-group v-model="rate" @change = "change()">
					<el-radio :label="1">待处理</el-radio>
					<el-radio :label="2">审核中</el-radio>
					<el-radio :label="3">同意</el-radio>
					<el-radio :label="4">拒绝</el-radio>
					<el-radio :label="5">已放款</el-radio>
					<el-radio :label="6">已还款</el-radio>
				</el-radio-group>
			</div>
			<div class="right-search1">
				<el-input v-model="input" placeholder="输入关键词…"></el-input>
				<el-button type="primary" @click="look()" style="margin-left: 10px;">查看</el-button>
				<el-button type="primary" @click="execl()">导出excel</el-button>
			</div>
		</div>
		<el-table :data="tableData" style="width: 100%">
			<el-table-column type="index" width="60">
			</el-table-column>
			<el-table-column prop="PName" label="商家名称">
			</el-table-column>
			<el-table-column prop="MemberName" label="用户姓名">
			</el-table-column>
			<el-table-column prop="Gender" label="用户性别">
			</el-table-column>
			<el-table-column prop="Tel" label="用户电话">
			</el-table-column>
			<el-table-column prop="TelYears" label="电话年限">
			</el-table-column>
			<!--<el-table-column prop="QQ" label="QQ号">
			</el-table-column>-->
			<el-table-column prop="WX" label="微信号">
			</el-table-column>
			<el-table-column prop="DemandDate" label="需求日期">
			</el-table-column>
			<el-table-column prop="DMoney" label="需求金额">
			</el-table-column>
			<el-table-column prop="Stauts" label="分配状态">
			</el-table-column>
		</el-table>
		<div class="pages">
			<el-pagination small :current-page="index" @current-change="handleCurrentChange" layout="prev, pager, next" :total="total" background prev-text='上一页' next-text='下一页'>
			</el-pagination>
		</div>
	</div>
</template>

<script>
	import api from '../../../api/api'
	export default {
		name: 'manquery',
		data() {
			return {
				index: 1,
				total: 1,
				loading: true,
				rate: 1, //分配
				input: '', //搜索
				tableData: []
			}
		},
		created() {
			this.getallotquery(this.index)
		},
		methods: {
			execl(){
				this.loading = true
				this.$axios.post(api.getallotquery, {
					"AllotStauts": this.rate,
					"PagePara": {
						"Para": this.input,
						"PageSize": 10,
						"PageIndex":this.index-1,
						"OrderbyString": "PName",
						 "ToExcel": true
					}
				}).then(res => {
					if(res.data.isOK){
						if(res.data.data.ExcelResult && res.data.data.ExcelResult.isOK) {
							this.loading = false
							var urls = res.data.data.ExcelResult.data.filePath
							window.location.href = api.host+'/template/'+urls
						} else{
							this.loading = false
							this.$message.error(res.data.data.ExcelResult.msg);
						}
					} else {
						if(res.data.msg == "Token无效" || res.data.msg == "Token缺失") {
							this.$router.push({
								path: '/admin'
							})
						} else {
							this.loading = false
							this.$message.error(res.data.msg);
						}
					}
				})
			},
			handleCurrentChange(val) {
				this.index = val
				this.getallotquery(this.index)
			},
			look() {
				this.index = 1
				this.getallotquery(this.index)
			},
			getallotquery(val) {
				this.$axios.post(api.getallotquery, {
					"AllotStauts": this.rate,
					"PagePara": {
						"Para": this.input,
						"PageSize": 10,
						"PageIndex":val-1,
						"OrderbyString": "PName",
						 "ToExcel": false
					}
				}).then(res => {
					if(res.data.isOK) {
						this.loading = false
						this.tableData = res.data.data.Data
						this.total = res.data.data.Items ? res.data.data.Items : 1
					} else {
						if(res.data.msg == "Token无效" || res.data.msg == "Token缺失") {
							this.$router.push({
								path: '/admin'
							})
						} else {
							this.loading = false
							this.$message.error(res.data.msg);
						}
					}
				})
			},
			change(){
				this.loading = true
				this.index = 1
				this.$axios.post(api.getallotquery, {
					"AllotStauts": this.rate,
					"PagePara": {
						"Para": "",
						"PageSize": 10,
						"PageIndex":this.index-1,
						"OrderbyString": "PName",
						 "ToExcel": false
					}
				}).then(res => {
					if(res.data.isOK) {
						this.loading = false
						this.tableData = res.data.data.Data
						this.total = res.data.data.Items ? res.data.data.Items : 1
					} else {
						if(res.data.msg == "Token无效" || res.data.msg == "Token缺失") {
							this.$router.push({
								path: '/admin'
							})
						} else {
							this.loading = false
							this.$message.error(res.data.msg);
						}
					}
				})
			}
		}
	}
</script>

<style>

</style>